﻿<UserControl x:Class="Rio.Manager.Application.Views.DashboardTabView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:validation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"
             xmlns:localValidation="clr-namespace:Rio.Manager.Application.Utils.Validation"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:behaviors="clr-namespace:Rio.Manager.Application.Behaviors"
             xmlns:mvvmLightCommand="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
             mc:Ignorable="d">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Skins/DashboardTabSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.DataContext>
        <Binding Path="DashboardTab"
                 Source="{StaticResource Locator}" />
    </UserControl.DataContext>

    <Grid Name="LayoutRoot">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="Loaded">
                <mvvmLightCommand:EventToCommand Command="{Binding InitializationCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>

        <StackPanel>
            <StackPanel HorizontalAlignment="Left"
                        Orientation="Horizontal"
                        localValidation:ValidationScope.Errors="{Binding ValidationErrors}"
                        Margin="10,10,0,0">
                <TextBlock TextWrapping="Wrap"
                           Text="{Binding StartPeriodLabel}"
                           d:LayoutOverrides="Width"
                           VerticalAlignment="Center" />
                <telerik:RadDatePicker x:Name="StartRadDatePicker"
                                       Margin="5,0,0,0"
                                       SelectedValue="{Binding StartDate, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
                                       VerticalAlignment="Center" />
                <TextBlock TextWrapping="Wrap"
                           Text="{Binding StopPeriodLabel}"
                           VerticalAlignment="Center"
                           Margin="5,0,0,0" />
                <telerik:RadDatePicker x:Name="EndRadDatePicker"
                                       Margin="5,0,0,0"
                                       SelectedValue="{Binding EndDate, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
                                       VerticalAlignment="Center" />
                <TextBlock TextWrapping="Wrap"
                           Text="."
                           VerticalAlignment="Center"
                           Margin="5,0,0,0" />
                <Button Margin="10,0,0,0"
                        Command="{Binding GenerateReportCommand}">
                    <StackPanel Orientation="Horizontal"
                                Margin="1">
                        <Image Source="/Rio.Manager.Application;component/Assets/Images/refresh.png"
                               Margin="0,0,3,0"
                               Width="20"
                               Height="20"
                               VerticalAlignment="Center" />
                        <TextBlock Text="{Binding GenerateButtonContent}"
                                   VerticalAlignment="Center" />
                    </StackPanel>

                    <i:Interaction.Behaviors>
                        <behaviors:ValidationDatesBehavior StartRadDatePicker="{Binding ElementName=StartRadDatePicker}"
                                                           EndRadDatePicker="{Binding ElementName=EndRadDatePicker}" />
                    </i:Interaction.Behaviors>
                </Button>
                <Button HorizontalAlignment="Right"
                        IsEnabled="{Binding TotalFoldersCount, Converter={StaticResource EnableExportReportButtonConverter}}"
                        Margin="10,0,0,0">
                    <StackPanel Orientation="Horizontal"
                                Margin="1">
                        <Image Source="/Rio.Manager.Application;component/Assets/Images/export.png"
                               Margin="0,0,3,0"
                               Width="20"
                               Height="20"
                               VerticalAlignment="Center" />
                        <TextBlock Text="{Binding ExportButtonContent}"
                                   VerticalAlignment="Center" />
                    </StackPanel>
                    <i:Interaction.Behaviors>
                        <behaviors:ExportReportBehavior UIElementToExport="{Binding ElementName=stackPanel, Mode=OneWay}" />
                    </i:Interaction.Behaviors>
                </Button>
            </StackPanel>

            <validation:ValidationSummary Style="{StaticResource ValidationSummaryStyle}"
                                          Margin="10,10,10,0">
            </validation:ValidationSummary>

            <Border BorderThickness="0,1,0,0"
                    Padding="20"
                    Margin="20"
                    BorderBrush="Black"
                    HorizontalAlignment="Center">
                <StackPanel x:Name="stackPanel"
                            Orientation="Vertical"
                            Margin="0">
                    <StackPanel Orientation="Horizontal"
                                HorizontalAlignment="Center">
                        <TextBlock TextWrapping="Wrap"
                                   Text="{Binding ReportStartLabel}"
                                   HorizontalAlignment="Center"
                                   FontWeight="Bold"
                                   FontSize="14.667"
                                   FontStyle="Italic" />
                        <TextBlock TextWrapping="Wrap"
                                   HorizontalAlignment="Center"
                                   Text="{Binding StartDate, StringFormat='dd/MM/yyyy'}"
                                   Margin="5,0,0,0"
                                   FontWeight="Bold"
                                   FontSize="14.667"
                                   FontStyle="Italic" />
                        <TextBlock TextWrapping="Wrap"
                                   Text="{Binding ReportStopLabel}"
                                   HorizontalAlignment="Center"
                                   Margin="5,0,0,0"
                                   FontWeight="Bold"
                                   FontSize="14.667"
                                   FontStyle="Italic" />
                        <TextBlock TextWrapping="Wrap"
                                   HorizontalAlignment="Center"
                                   Text="{Binding EndDate, StringFormat='dd/MM/yyyy'}"
                                   Margin="5,0,0,0"
                                   FontWeight="Bold"
                                   FontSize="14.667"
                                   FontStyle="Italic" />
                    </StackPanel>
                    <Grid Margin="15,30,15,0"
                          HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Center"
                                   TextWrapping="Wrap"
                                   Text="{Binding GlobalInformation}"
                                   FontSize="13.333"
                                   FontWeight="Bold"
                                   Grid.ColumnSpan="2"
                                   VerticalAlignment="Center" />
                        <!--<TextBlock TextWrapping="Wrap"
                                   Text="{Binding TaskProgress}"
                                   FontSize="13.333"
                                   FontWeight="Bold"
                                   Grid.Column="1"
                                   d:LayoutOverrides="Width, Height"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center" />-->
                        <Border Grid.ColumnSpan="2"
                                Grid.Row="1"
                                BorderThickness="1"
                                BorderBrush="Black"
                                Padding="20"
                                Margin="0,10,0,0">
                            <Border.Effect>
                                <DropShadowEffect />
                            </Border.Effect>
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,1"
                                                     StartPoint="0.5,0">
                                    <GradientStop Color="#FFCACACA"
                                                  Offset="0" />
                                    <GradientStop Color="White"
                                                  Offset="1" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <StackPanel Orientation="Horizontal"
                                            Grid.Row="1"
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"
                                            Margin="0,15,0,0">
                                    <StackPanel Orientation="Horizontal">
                                        <Image Margin="0,0,5,0"
                                               Source="/Rio.Manager.Application;component/Assets/Images/folder_closed.png" />
                                        <TextBlock TextWrapping="Wrap"
                                                   Text="{Binding StrTotalFoldersCount}"
                                                   d:LayoutOverrides="Width"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center" />
                                        <TextBlock TextWrapping="Wrap"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,0,0"
                                                   Text="{Binding TotalFoldersCount}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"
                                                Margin="10,0,0,0">
                                        <Image Margin="0,0,5,0"
                                               Source="/Rio.Manager.Application;component/Assets/Images/folder_scanned.png" />
                                        <TextBlock TextWrapping="Wrap"
                                                   Text="{Binding StrNbFolderProcessed}"
                                                   d:LayoutOverrides="Width"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center" />
                                        <TextBlock TextWrapping="Wrap"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,0,0"
                                                   Text="{Binding FoldersProcessed}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"
                                                Margin="10,0,0,0"
                                                Visibility="Collapsed">
                                        <Image Margin="0,0,5,0"
                                               Source="/Rio.Manager.Application;component/Assets/Images/folder_closed.png" />
                                        <TextBlock HorizontalAlignment="Center"
                                                   TextWrapping="Wrap"
                                                   Text="{Binding StrNbFolderClose}"
                                                   Margin="0"
                                                   VerticalAlignment="Center" />
                                        <TextBlock TextWrapping="Wrap"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,0,0"
                                                   Text="{Binding FoldersClosed}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"
                                                Margin="10,0,0,0">
                                        <Image Margin="5,0,3,0"
                                               Source="/Rio.Manager.Application;component/Assets/Images/folder_to_review.png"
                                               Width="30"
                                               Height="30" />
                                        <TextBlock HorizontalAlignment="Center"
                                                   TextWrapping="Wrap"
                                                   Text="{Binding StrNbFolderIncomplete}"
                                                   Margin="0"
                                                   VerticalAlignment="Center" />
                                        <TextBlock TextWrapping="Wrap"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,0,0"
                                                   Text="{Binding FoldersToReview}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"
                                                Margin="10,0,0,0">
                                        <Image Margin="5,0,7,0"
                                               Source="/Rio.Manager.Application;component/Assets/Images/document.png" />
                                        <TextBlock HorizontalAlignment="Center"
                                                   TextWrapping="Wrap"
                                                   Text="{Binding StrNbFileScan}"
                                                   Margin="0"
                                                   VerticalAlignment="Center" />
                                        <TextBlock TextWrapping="Wrap"
                                                   HorizontalAlignment="Center"
                                                   VerticalAlignment="Center"
                                                   Margin="5,0,0,0"
                                                   Text="{Binding FilesScanned}" />
                                    </StackPanel>
                                </StackPanel>
                                <telerik:RadChart ItemsSource="{Binding FoldersChartList}"
                                                  Content=""
                                                  BorderBrush="Black"
                                                  Width="500"
                                                  Height="400"
                                                  BorderThickness="0"
                                                  HorizontalAlignment="Center"
                                                  Grid.Column="1"
                                                  Margin="10,0,0,0">
                                    <telerik:RadChart.SeriesMappings>
                                        <telerik:SeriesMapping>
                                            <telerik:SeriesMapping.SeriesDefinition>
                                                <telerik:PieSeriesDefinition />
                                            </telerik:SeriesMapping.SeriesDefinition>
                                            <telerik:ItemMapping DataPointMember="Label"
                                                                 FieldName="Label" />
                                            <telerik:ItemMapping DataPointMember="YValue"
                                                                 FieldName="Value" />
                                        </telerik:SeriesMapping>
                                    </telerik:RadChart.SeriesMappings>
                                    <telerik:RadChart.DefaultView>
                                        <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                                            <telerik:ChartDefaultView.ChartArea>
                                                <telerik:ChartArea SmartLabelsEnabled="true" />
                                            </telerik:ChartDefaultView.ChartArea>
                                            <telerik:ChartDefaultView.ChartLegend>
                                                <telerik:ChartLegend Visibility="Collapsed" />
                                            </telerik:ChartDefaultView.ChartLegend>
                                        </telerik:ChartDefaultView>
                                    </telerik:RadChart.DefaultView>
                                </telerik:RadChart>
                            </Grid>
                        </Border>
                    </Grid>
                    <Grid Margin="15,30,15,15"
                          HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock TextWrapping="Wrap"
                                   Text="{Binding UserInformation}"
                                   HorizontalAlignment="Center"
                                   FontSize="13.333"
                                   FontWeight="Bold"
                                   VerticalAlignment="Center"
                                   Grid.ColumnSpan="2" />
                        <Border Grid.Row="1"
                                Grid.ColumnSpan="2"
                                d:LayoutOverrides="Width, Height"
                                BorderThickness="1"
                                BorderBrush="Black"
                                Padding="20"
                                Margin="0,10,0,0">
                            <Border.Effect>
                                <DropShadowEffect />
                            </Border.Effect>
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,1"
                                                     StartPoint="0.5,0">
                                    <GradientStop Color="#FFE0E0E0"
                                                  Offset="0" />
                                    <GradientStop Color="White"
                                                  Offset="1" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <StackPanel Grid.Row="1"
                                            VerticalAlignment="Stretch"
                                            HorizontalAlignment="Stretch"
                                            Margin="0,15,0,0">
                                    <ScrollViewer x:Name="scrollViewer"
                                                  HorizontalAlignment="Stretch"
                                                  HorizontalContentAlignment="Stretch"
                                                  ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                  BorderThickness="0">
                                        <telerik:RadGridView x:Name="radGridView"
                                                             AutoGenerateColumns="False"
                                                             ShowColumnFooters="True"
                                                             ShowGroupFooters="True"
                                                             HorizontalAlignment="Stretch"
                                                             HorizontalContentAlignment="Stretch"
                                                             ItemsSource="{Binding Operators, Mode=OneWay}"
                                                             GroupPanelStyle="{StaticResource GridViewGroupPanelStyle}"
                                                             SelectionChanged="radGridView_SelectionChanged"
                                                             SelectionMode="Extended"
                                                             SelectionUnit="FullRow"
                                                             BorderThickness="1"
                                                             BorderBrush="#FFD0D0D0"
                                                             AlternateRowBackground="#FFE5F1FF"
                                                             AlternationCount="2">

                                            <telerik:RadGridView.Columns>
                                                <telerik:GridViewDataColumn Header="{Binding DashboardTab.TitleColumnUserName, Source={StaticResource Locator}, Mode=OneWay}"
                                                                            DataMemberBinding="{Binding FullName}"
                                                                            IsReadOnly="True">
                                                    <telerik:GridViewDataColumn.Footer>
                                                        <TextBlock Text="{Binding DashboardTab.TitleRowTotalSum, Source={StaticResource Locator}, Mode=OneWay}" />
                                                    </telerik:GridViewDataColumn.Footer>
                                                </telerik:GridViewDataColumn>
                                                <telerik:GridViewDataColumn Header="{Binding DashboardTab.TitleColumnNbFolderProcessed, Source={StaticResource Locator}, Mode=OneWay}"
                                                                            DataMemberBinding="{Binding NbFolderProcessed}"
                                                                            IsReadOnly="True">
                                                    <telerik:GridViewDataColumn.AggregateFunctions>
                                                        <telerik:SumFunction />
                                                    </telerik:GridViewDataColumn.AggregateFunctions>
                                                </telerik:GridViewDataColumn>
                                                <telerik:GridViewDataColumn Header="{Binding DashboardTab.TitleColumnNbFileScan, Source={StaticResource Locator}, Mode=OneWay}"
                                                                            DataMemberBinding="{Binding NbFileScan}"
                                                                            IsReadOnly="True">
                                                    <telerik:GridViewDataColumn.AggregateFunctions>
                                                        <telerik:SumFunction />
                                                    </telerik:GridViewDataColumn.AggregateFunctions>
                                                </telerik:GridViewDataColumn>
                                            </telerik:RadGridView.Columns>
                                        </telerik:RadGridView>
                                    </ScrollViewer>

                                    <Button Margin="0,10,10,0"
                                            HorizontalAlignment="Right"
                                            IsEnabled="{Binding ItemsSource, ElementName=radGridView, Converter={StaticResource EnableExportExcelButtonConverter}}">
                                        <StackPanel Orientation="Horizontal"
                                                    Margin="1">
                                            <Image Source="/Rio.Manager.Application;component/Assets/Images/excel.png"
                                                   Margin="0,0,3,0"
                                                   Width="16"
                                                   Height="16"
                                                   VerticalAlignment="Center" />
                                            <TextBlock Text="{Binding ExportDataButtonContent}"
                                                       VerticalAlignment="Center" />
                                        </StackPanel>

                                        <i:Interaction.Behaviors>
                                            <behaviors:ExportExcelGridViewBehavior GridViewToExport="{Binding ElementName=radGridView, Mode=OneWay}" />
                                        </i:Interaction.Behaviors>
                                    </Button>

                                </StackPanel>
                                <StackPanel Orientation="Horizontal"
                                            HorizontalAlignment="Stretch"
                                            Margin="0">
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="{Binding TitleColumnNbFolderProcessed}"
                                                   HorizontalAlignment="Center"
                                                   FontWeight="Bold"
                                                   FontSize="11"
                                                   Margin="0,0,0,5" />
                                        <telerik:RadChart ItemsSource="{Binding SelectedOperators}"
                                                          Content=""
                                                          BorderBrush="Black"
                                                          Width="500"
                                                          Height="400"
                                                          BorderThickness="0"
                                                          d:LayoutOverrides="HorizontalMargin">
                                            <telerik:RadChart.SeriesMappings>
                                                <telerik:SeriesMapping>
                                                    <telerik:SeriesMapping.SeriesDefinition>
                                                        <telerik:PieSeriesDefinition />
                                                    </telerik:SeriesMapping.SeriesDefinition>
                                                    <telerik:ItemMapping DataPointMember="Label"
                                                                         FieldName="FullName" />
                                                    <telerik:ItemMapping DataPointMember="YValue"
                                                                         FieldName="NbFolderProcessed" />
                                                </telerik:SeriesMapping>
                                            </telerik:RadChart.SeriesMappings>
                                            <telerik:RadChart.DefaultView>
                                                <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                                                    <telerik:ChartDefaultView.ChartArea>
                                                        <telerik:ChartArea SmartLabelsEnabled="true"
                                                                           Margin="0" />
                                                    </telerik:ChartDefaultView.ChartArea>
                                                    <telerik:ChartDefaultView.ChartLegend>
                                                        <telerik:ChartLegend Visibility="Collapsed" />
                                                    </telerik:ChartDefaultView.ChartLegend>
                                                </telerik:ChartDefaultView>
                                            </telerik:RadChart.DefaultView>
                                        </telerik:RadChart>
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock Text="{Binding FoldersProcessedByOperatorsByDate}"
                                                   HorizontalAlignment="Center"
                                                   FontWeight="Bold"
                                                   FontSize="11"
                                                   Margin="0,0,0,5" />
                                        <telerik:RadChart BorderBrush="Black"
                                                          Height="400"
                                                          BorderThickness="0"
                                                          d:LayoutOverrides="HorizontalMargin"
                                                          Margin="10,0,0,0"
                                                          ItemsSource="{Binding FoldersTimeChart}">
                                            <telerik:RadChart.SeriesMappings>
                                                <telerik:SeriesMapping>
                                                    <telerik:SeriesMapping.SeriesDefinition>
                                                        <telerik:BarSeriesDefinition />
                                                    </telerik:SeriesMapping.SeriesDefinition>
                                                    <telerik:ItemMapping DataPointMember="XCategory"
                                                                         FieldName="Date" />
                                                    <telerik:ItemMapping DataPointMember="YValue"
                                                                         FieldName="NbFoldersProcessed" />
                                                </telerik:SeriesMapping>
                                            </telerik:RadChart.SeriesMappings>
                                            <telerik:RadChart.DefaultView>
                                                <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                                                    <telerik:ChartDefaultView.ChartArea>
                                                        <telerik:ChartArea SmartLabelsEnabled="true">
                                                            <telerik:ChartArea.AxisX>
                                                                <telerik:AxisX LabelRotationAngle="45"
                                                                               DefaultLabelFormat="dd-MM-yyyy" />
                                                            </telerik:ChartArea.AxisX>
                                                        </telerik:ChartArea>
                                                    </telerik:ChartDefaultView.ChartArea>
                                                    <telerik:ChartDefaultView.ChartLegend>
                                                        <telerik:ChartLegend Visibility="Collapsed" />
                                                    </telerik:ChartDefaultView.ChartLegend>
                                                </telerik:ChartDefaultView>
                                            </telerik:RadChart.DefaultView>
                                        </telerik:RadChart>
                                    </StackPanel>
                                </StackPanel>
                            </Grid>
                        </Border>
                    </Grid>
                </StackPanel>
            </Border>
        </StackPanel>

        <telerik:RadBusyIndicator IsBusy="{Binding BusyIndicator.IsBusy}"
                                  IsIndeterminate="True">
        </telerik:RadBusyIndicator>
    </Grid>
</UserControl>